/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utils;

/**
 *
 * @author Odotube
 */
public class Time {

    private int mHour;
    private int mMin;
    private int mSec;

    public Time(int mHour, int mMin, int mSec) {
        this.mHour = mHour;
        this.mMin = mMin;
        this.mSec = mSec;
    }

    public void setHour(int mHour) {
        this.mHour = mHour;
    }

    public int getHour() {
        return this.mHour;
    }

    public void setMin(int mMin) {
        this.mMin = mMin;
    }

    public int getMin() {
        return this.mMin;
    }

    public void setSec(int mSec) {
        this.mSec = mSec;
    }

    public int getSec() {
        return this.mSec;
    }

    public static Time parseTime(String time) {
        String[] data = time.split(":");
        if (data.length == 3) {
            try {
                int hour = Integer.parseInt(data[0]);
                if (hour < 0 || hour > 23) {
                    return null;
                }
                int min = Integer.parseInt(data[1]);
                if (min < 0 || min > 59) {
                    return null;
                }
                int sec = Integer.parseInt(data[2]);
                if (sec < 0 || sec > 59) {
                    return null;
                }
                return new Time(hour, min, sec);
            } catch (NumberFormatException ex) {
                return null;
            }
        }
        return null;
    }

    public boolean equals(Time time) {
        return (this.mHour == time.getHour() && this.mMin == time.getMin() && this.mSec == time.getSec());
    }

    public int compare(Time time) {
        if (this.mHour < time.getHour()) {
            return -1;
        } else if (this.mHour > time.getHour()) {
            return 1;
        } else {
            if(this.mMin < time.getMin()){
                return -1;
            } else if(this.mMin>time.getMin()){
                return 1;
            } else {
                if(this.mSec<time.getSec()){
                    return -1;
                } else if(this.mSec>time.getSec()){
                    return 1;
                }
            }
        }
        return 0;
    }
    public String toString(){
        return new String(this.mHour+":"+this.mMin+":"+this.mSec);
    }
    public static void main(String[] args){
        System.out.println(Time.parseTime("8:0:0").toString());
        System.out.println(Date.parseDate("17/09/2012").toString());
    }
}
